package Change.dao.hibernate;

import Change.dao.InterestDao;
import Change.model.Interest;

import java.util.List;
import java.util.ArrayList;

public class InterestDaoHibernate extends GenericDaoHibernate<Interest, Long> implements
		InterestDao {

	public InterestDaoHibernate(){
		super(Interest.class);
	}
	
	public List<Interest> getInterests(Long parentId){
		List<Interest> result = new ArrayList<Interest>();
		if (null == parentId) {
			result = getHibernateTemplate().find("from Interest where parent_id is null");
		} else {
			result = getHibernateTemplate().find("from Interest where parent_id = ?", parentId);
		}
		
		return result;
	}
	
	public Interest getInterest(Long id){
		return (Interest) getHibernateTemplate().find("from Interest where id = ?", id).get(0);
	}
}
